<template>
		<div id="my_note">
			<div class="nav">
				<ul class="am-avg-sm-2">
					<li><a @click="uni.redirectTo({url:'../../../pages/add/my_note'})">已发表</a></li>
					<li><a class="cur" @click="uni.redirectTo({
					url:''
				})">草稿箱</a></li>
				</ul>
			</div>
			<div class="cont">
				<div id="app">
					<ul v-for="(b,index) in articles" :key="index">
						<li>
							<div class="box_cont" @click="itemClicked(b)">
								<a title="" @click="uni.navigateTo({
									url:'../../../pages/main/beautiful_detail?id='+b.id,
							})">
									<div class="pic">
										<img :src="'https://yo.docshare.org.cn'+b.background">
									</div>
									<div class="project_cont">
										<p>{{b.articletitle}}</p>
									</div>
									<div class="clear"></div>
								</a>
							</div>
							<span class="date">{{b.articletime}}</span>
							<div class="button" style="display: flex;">
								<button type="submit"  @click="deletebox(b)" value="删除" >删除</button>
															<button type="submit" class="gray_hollow" @click="release(b)" value="发布" style="display: flex;
								justify-content: center;
								align-items: center;">发布</button>
							</div>
						</li>
					</ul>
				</div>
			</div>
		</div>
</template>

<script>
	import config from '@/config'
	export default {
		data() {
			return {
				uni,
				config,
				aid: '',
				articles: [],
				id: '',
			}
		},
		methods: {
			itemClicked: function(item) {
				this.id = item.id;
			},
			deletebox: function(item) {
				this.id = item.id;
				uni.request({
					url: `${config.baseUrl}/article/deletebox?token=` + uni.getStorageSync('token'),
					data: {
						id: this.id,
					},
					method: 'POST',
					success(r) {
						if (r.data.succ) {
							uni.navigateTo({
								url: 'box'
							})
						} else {}
					},
					complete(res){
						if(res.data && res.data.msg){
							uni.showToast({
								icon:'none',
								title:res.data.msg
							})
						}
					},
				});
			},
			release: function(item) {
				this.id = item.id;
				uni.request({
					url: `${config.baseUrl}/article/releasebox?token=` + uni.getStorageSync('token'),
					data: {
						id: this.id,
					},
					method: 'POST',
					success(r) {
						if (r.data.succ) {
							uni.navigateTo({
								url: 'box'
							})
						} else {}
					},
					complete(res){
						if(res.data && res.data.msg){
							uni.showToast({
								icon:'none',
								title:res.data.msg
							})
						}
					},
				});
			},
		},
		onLoad() {
			var that = this;
			uni.request({
				url: `${config.baseUrl}/article/box?token=${uni.getStorageSync('token')}`,
				method: "GET",
				success(r) {
					if (r.data.succ) {
						that.articles = r.data.data;
					} else {

					}
				},
					complete(res){
						if(res.data && res.data.msg){
							uni.showToast({
								icon:'none',
								title:res.data.msg
							})
						}
					},
			})
		}
	}
</script>

<style>

</style>
